<?php

/**
 * main.php
 *
 * This file holds frontend configuration settings.
 */
$frontendConfigDir = dirname(__FILE__);

$params = require_once($frontendConfigDir . DIRECTORY_SEPARATOR . 'params.php');

// Setup some default path aliases. These alias may vary from projects.
Yii::setPathOfAlias('root', ROOT);
Yii::setPathOfAlias('common', ROOT . DIRECTORY_SEPARATOR . 'common');
Yii::setPathOfAlias('backend', ROOT . DIRECTORY_SEPARATOR . 'backend' . DIRECTORY_SEPARATOR . 'protected');
Yii::setPathOfAlias('www', ROOT . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'www');

$mainLocalFile = $frontendConfigDir . DIRECTORY_SEPARATOR . 'main-local.php';
$mainLocalConfiguration = file_exists($mainLocalFile) ? require($mainLocalFile) : array();

$mainEnvFile = $frontendConfigDir . DIRECTORY_SEPARATOR . 'main-env.php';
$mainEnvConfiguration = file_exists($mainEnvFile) ? require($mainEnvFile) : array();

return CMap::mergeArray(
		array(
	    // @see http://www.yiiframework.com/doc/api/1.1/CApplication#basePath-detail
	    'basePath' => $frontendConfigDir . DIRECTORY_SEPARATOR . '..',
	    // set parameters
	    'params' => $params,
	    // preload components required before running applications
	    // @see http://www.yiiframework.com/doc/api/1.1/CModule#preload-detail
	    'preload' => array('log', 'bootstrap'),
	    // @see http://www.yiiframework.com/doc/api/1.1/CApplication#language-detail
	    'language' => 'en',
	    // uncomment if a theme is used
	    /* 'theme' => '', */
	    // setup import paths aliases
	    // @see http://www.yiiframework.com/doc/api/1.1/YiiBase#import-detail
	    'import' => array(
		'common.components.*',
		'common.components.helpers.*',
		'common.models.*',
		'common.models.user.*',
		'common.models.adv.*',
		'common.models.ad.*',
		'application.components.*',
		'application.models.*',
	    ),
	    /* uncomment and set if required */
	    // @see http://www.yiiframework.com/doc/api/1.1/CModule#setModules-detail
	    /* 'modules' => array(), */
	    'components' => array(
		'errorHandler' => array(
		    // @see http://www.yiiframework.com/doc/api/1.1/CErrorHandler#errorAction-detail
		    'errorAction' => 'site/error'
		),
		'user' => array(
		    // enable cookie-based authentication
		    'allowAutoLogin' => true,
		    'class' => 'WebUser'
		),
		/* load bootstrap components */
		'bootstrap' => array(
		    'class' => 'common.extensions.bootstrap.components.Bootstrap',
		    'responsiveCss' => true,
		),
		'db' => $params['db.connect'],
		'urlManager' => array(
		    'urlFormat' => 'path',
		    'showScriptName' => false,
		    'urlSuffix' => '',
		    'rules' => $params['url.rules']
		),
		'settings' => $params['settings'],
		'cache' => $params['cache.file'],
		'log' => array(
		    'class' => 'CLogRouter',
		    'routes' => array(
			array(
			    'class' => 'CWebLogRoute', 'levels' => 'trace, info, error, warning',
			),
			array(
			    'class' => 'CFileLogRoute', 'levels' => 'trace, info, error, warning',
			),
		    )
		),
		/* load bootstrap components */
		'bootstrap' => array(
		    'class' => 'common.extensions.bootstrap.components.Bootstrap',
		    'coreCss' => false
		//'responsiveCss' => false,
		),
		'Paypal' => $params['Paypal'],
	    /* make sure you have your cache set correctly before uncommenting */
	    /* 'cache' => $params['cache.core'], */
	    /* 'contentCache' => $params['cache.content'] */
	    ),
	    'modules' => array(
		'blog', 'user',
		'comments' => array(
		    //you may override default config for all connecting models
		    'defaultModelConfig' => array(
			//only registered users can post comments
			'registeredOnly' => false,
			'useCaptcha' => false,
			//allow comment tree
			'allowSubcommenting' => true,
			//display comments after moderation
			'premoderate' => false,
			//action for postig comment
			'postCommentAction' => 'comments/comment/postComment',
			//super user condition(display comment list in admin view and automoderate comments)
			//'isSuperuser'=>'Yii::app()->user->checkAccess("moderate")',
			//order direction for comments
			'orderComments' => 'DESC',
		    ),
		    //the models for commenting
		    'commentableModels' => array(
			//model with individual settings
			'Post' => array(
			    'registeredOnly' => false,
			    'useCaptcha' => false,
			    'allowSubcommenting' => false,
			//config for create link to view model page(page with comments)
//                                'pageUrl'=>array(
//                                    'route'=>'admin/posts/view',
//                                    'data'=>array('id'=>'city_id'),
//                                ),
			),
			//model with default settings
			'ImpressionSet',
		    ),
		    //config for user models, which is used in application
		    'userConfig' => array(
			'class' => 'User',
			'nameProperty' => 'username',
			'emailProperty' => 'email',
		    ),
		),
	    )
		), CMap::mergeArray($mainEnvConfiguration, $mainLocalConfiguration)
);